﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="lp_Configuration_below.aspx.cs"
    Inherits="ZLDC.Estate.Quantify.lp_Configuration_below" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>工作分配</title>
    <link href="css/page.css" rel="stylesheet" type="text/css" />

    <script src="flexigrid/jquery.js" type="text/javascript"></script>

    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <link href="css/page.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        input
        {
            text-align: center;
        }
       
    </style>

    <script src="js/lp_Basis.js" type="text/javascript"></script>

    <script type="text/javascript">
        function bindGrid() {
            $("#table2").flexigrid(
			{
			    sortname: "",
			    sortorder: "asc",
			    sortable: true,
			    usepager: false,
			    title: false,
			    rocmsg: '正在查询，请稍等...', //正在处理的提示信息
			    nomsg: '没有记录',
			    showTableToggleBtn: true,
			    width: "600",
			    height: "250"
			}
		    );
            $("#table1").flexigrid(
			{
			    sortname: "",
			    sortorder: "asc",
			    sortable: true,
			    usepager: false,
			    title: false,
			    rocmsg: '正在查询，请稍等...', //正在处理的提示信息
			    nomsg: '没有记录',
			    showTableToggleBtn: true,
			    width: "600",
			    height: "250"
			}
		    );
        }
        function CheckAll(o) {
            $("#table1 tbody input[@type=checkbox]").attr("checked", o.checked);
        }

        function Knum(obj, tablename, n) {
            var rowIndex = obj.parentNode.parentNode.rowIndex;
            var tbcell3 = document.getElementById(tablename).rows[rowIndex].cells[3].innerHTML; //分值
            var tbcell4 = document.getElementById(tablename).rows[rowIndex].cells[7].innerHTML; //数量
            var tbcell5 = document.getElementById(tablename).rows[rowIndex].cells[4].childNodes[0].value; //最高分
            var tbcell6 = document.getElementById(tablename).rows[rowIndex].cells[5].childNodes[0].value; //完成数量
            var tbcell7 = document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value; //单项总分
            var tbcell0 = document.getElementById(tablename).rows[rowIndex].cells[1].childNodes[0].checked;
            var checkdisabled = document.getElementById(tablename).rows[rowIndex].cells[1].childNodes[0].disabled; //是否默认菜单项
            var hidQuantity = document.getElementById(tablename).rows[rowIndex].cells[2].childNodes[7].value; //完成数量 hid
           
            if (checkdisabled) {
                if (parseInt(obj.value) < parseInt(hidQuantity)) {
                    obj.value = hidQuantity;
                }
            }
            else {
                if (!tbcell0) {//如果打勾false则都为0
                   
                        document.getElementById(tablename).rows[rowIndex].cells[5].childNodes[0].value = '0'; //完成数量
                        document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value = '0'; //单项总分
                        document.getElementById(tablename).rows[rowIndex].cells[5].childNodes[0].disabled = (tbcell0 == true ? false : true);
                  
                }
            }


           
            
            var Agg = 0;
           
            if (tbcell5 ==0) {

                Agg = parseInt(obj.value) / parseInt(tbcell4) * parseInt(tbcell3);

                document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value = parseInt(Agg);
            }
            else {

                Agg = parseInt(obj.value) / parseInt(tbcell4) * parseInt(tbcell3);
                
                if (Agg > parseInt(tbcell5 == 'NaN' ? '0' : tbcell5)) {

                    document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value = parseInt(tbcell5 == NaN ? '0' : tbcell5)
                }
                else
                { document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value = parseInt(Agg); }
            }
            if (tbcell6 == '') {
                document.getElementById(tablename).rows[rowIndex].cells[5].childNodes[0].value = '0';

            }
            
//            else {
            //document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value = (Agg == NaN ? '0' : Agg);
           
            //}
            if (document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value == 'NaN') {
                document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value = '0'
            }
            var tabnumn = 0;

            for (var i = 1; i < document.getElementById(tablename).rows.length - 2; i++) {
                if (document.getElementById(tablename).rows[i].cells[1].childNodes[0].checked || document.getElementById(tablename).rows[i].cells[1].childNodes[0].disabled) {
                    tabnumn += parseInt(document.getElementById(tablename).rows[i].cells[6].childNodes[0].value == '' ? '0' : parseInt(document.getElementById(tablename).rows[i].cells[6].childNodes[0].value));
                    document.getElementById(tablename).rows[i].cells[5].childNodes[0].disabled = false;
                }
            }

            document.getElementById('txtallnum' + n).value = tabnumn;
            if (parseInt(document.getElementById('txtallnum' + n).value) > parseInt(document.getElementById('txtTotal' + n).value)) {
                document.getElementById('btnAdd').value = "保存工作设置(设置分数大于最低分数)";
            }
            else {
                document.getElementById('btnAdd').value = "保存工作设置(设置分数小于最低分数)";
            }

        }


        window.onload = function() {
      
            var dropPK = document.getElementById('dropPK');

            var index = dropPK.selectedIndex; //序号，取当前选中选项的序号

            var val = dropPK.options[index].text;
            var tablename = document.getElementById('table2');
            if (val == '请选择') {
                tablename = document.getElementById('table1');

            }
            tablename.rows[1].cells[0].rowSpan = '6';
            for (var i = 2; i < 7; i++) {
                tablename.rows[i].cells[0].style.display = 'none';
            }
            tablename.rows[7].cells[0].rowSpan = '7';
            for (var i = 8; i < 14; i++) {
                tablename.rows[i].cells[0].style.display = 'none';
            }

            if (val != "请选择") {
                var tabnumn = 0;
                var tablename = 'table2';
                for (var i = 1; i < document.getElementById(tablename).rows.length - 2; i++) {
                    if (document.getElementById(tablename).rows[i].cells[1].childNodes[0].checked || document.getElementById(tablename).rows[i].cells[1].childNodes[0].disabled) {
                        tabnumn += parseInt(document.getElementById(tablename).rows[i].cells[6].childNodes[0].value == '' ? '0' : parseInt(document.getElementById(tablename).rows[i].cells[6].childNodes[0].value));
                      
                    }
                }
                document.getElementById('txtallnum2').value = tabnumn;
                if (parseInt(document.getElementById('txtallnum2').value) > parseInt(document.getElementById('txtTotal2').value)) {
                    document.getElementById('btnAdd').value = "保存工作设置(设置分数大于最低分数)";
                }
                else {
                    document.getElementById('btnAdd').value = "保存工作设置(设置分数小于最低分数)";
                }

            }
            
        }


       
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <%=showTime %>
        <span id="sptc" runat="server">套餐：
            <asp:DropDownList ID="dropPK" runat="server" AutoPostBack="True" OnSelectedIndexChanged="dropPK_SelectedIndexChanged">
            </asp:DropDownList>
        </span>
        <div>
            <asp:Panel ID="Panel2" runat="server" Width="95%">
                <table id="table2" width="560px" border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>
                    <thead>
                        <tr>
                            <th align="center" width="60px" bgcolor='d3eaef' class='STYLE6'>
                                类别
                            </th>
                            <th align="center" width="60px" bgcolor='d3eaef' class='STYLE6'>
                                编码
                            </th>
                            <th align="center" width="25%" bgcolor='d3eaef' class='STYLE6'>
                                工作
                            </th>
                            <th align="center" width="60px" bgcolor='d3eaef' class='STYLE6'>
                                分值
                            </th>
                            <th align="center" width="60px" bgcolor='d3eaef' class='STYLE6'>
                                最高分
                            </th>
                            <th align="center" width="60px" bgcolor='d3eaef' class='STYLE6'>
                                完成数量
                            </th>
                            <th align="center" width="60px" bgcolor='d3eaef' class='STYLE6'>
                                单项总分
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <asp:Repeater ID="RpList" runat="server">
                            <ItemTemplate>
                                <tr>
                                    <td class='STYLE10'  >
                                       <%# Eval("Other1")%>
                                    </td>
                                    <td class='STYLE10'>
                                        <asp:CheckBox ID="ckb" runat="server"  Enabled='<%#  ZLDC.Topo.BLL.Estate.lp_Package.GetEnabled(Eval("Choosesj").ToString()) %>' Checked='<%# Gettr(Eval("Choose").ToString()) %>'
                                            onclick='Knum(this,"table2",2)' />
                                        <asp:HiddenField ID="hidid" runat="server" Value='<%# Eval("BasisCode") %>' />
                                    </td>
                                    <td class='STYLE10'>
                                        <%# Eval("BasisName")%>
                                        <%# Eval("CompleteNum") %>
                                        <asp:HiddenField ID="hidCompleteNum" runat="server" Value='<%# Eval("CompleteNum") %>' />
                                        <asp:HiddenField ID="hidPoint" runat="server" Value='<%# Eval("Point") %>' />
                                        <asp:HiddenField ID="hidName" runat="server" Value='<%# Eval("BasisName") %>' />
                                          <asp:HiddenField ID="hidQuantity" runat="server" Value='<%# Eval("Quantity") %>' />
                                        <asp:HiddenField ID="TypeName" runat="server" Value='<%# Eval("Other1") %>' />
                                       
                                        <%# Eval("Unit") %>
                                    </td>
                                    <td class='STYLE10'>
                                        <%# Eval("Point")%>
                                    </td>
                                    <td class='STYLE10' style="text-align: center">
                                        <asp:HiddenField ID="txtScore" runat="server" Value='<%# Eval("Score") %>' />
                                        <%# Eval("Score") %>
                                    </td>
                                    <td class='STYLE10'>
                                        <asp:TextBox ID="txtQuantity" Width="95%" onkeydown="myKeyDown()" onkeyup='Knum(this,"table2",2)' MaxLength="3"
                                            runat="server" Text='<%# Eval("Quantity") %>'></asp:TextBox>
                                    </td>
                                    <td class='STYLE10' style="text-align: center">
                                        <asp:TextBox ID="txtSinglePoint" Width="95%" onkeydown="myKeyDown()" BorderStyle="None" contenteditable="false"
                                            runat="server"></asp:TextBox>
                                    </td>
                                    <td class='STYLE10' style="display: none">
                                        <%# Eval("CompleteNum") %>
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                        <tr>
                            <td>
                                总分:
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                                <input id="txtallnum2" style="width: 50px; color: Red" value="0" runat="server" name="txtallnum2"
                                    type="text" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                最低总分:
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                               
                            </td> <td>
                                </td>
                            <td>
                                <input id="txtTotal2" style="width: 50px; color: Red" value="0" runat="server" name="txtTotal2"
                                    readonly="readonly" type="text" />
                            </td>
                        </tr>
                    </tbody>
                </table>
            </asp:Panel>
            <asp:Panel ID="Panel1" runat="server" Width="95%" Visible="false">
                <table id="table1" width="560px" border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>
                    <thead>
                        <tr>
                            <th align="center" width="60px" bgcolor='d3eaef' class='STYLE6'>
                                类别
                            </th>
                            <th align="center" width="60px" bgcolor='d3eaef' class='STYLE6'>
                                <input name='chkAll' type='checkbox' id='chkAll' onclick='CheckAll(this)' value='checkbox' />
                                编码
                            </th>
                            <th align="center" width="25%" bgcolor='d3eaef' class='STYLE6'>
                                工作项
                            </th>
                            <th align="center" width="60px" bgcolor='d3eaef' class='STYLE6'>
                                分值
                            </th>
                            <th align="center" width="60px" bgcolor='d3eaef' class='STYLE6'>
                                最高分
                            </th>
                            <th align="center" width="60px" bgcolor='d3eaef' class='STYLE6'>
                                完成数量
                            </th>
                            <th align="center" width="60px" bgcolor='d3eaef' class='STYLE6'>
                                单项总分
                            </th>
                            
                        </tr>
                    </thead>
                    <tbody>
                        <asp:Repeater ID="Repeater1" runat="server">
                            <ItemTemplate>
                                <tr>
                                    <td class='STYLE10' >
                                        <%# Eval("TypeName")%>
                                    </td>
                                    <td class='STYLE10'>
                                        <asp:CheckBox ID="ckb" runat="server"  Checked='<%# Eval("Other1").ToString()=="1"?true:false %>'
                                            onclick='Knum(this,"table1",1)' />
                                        <asp:HiddenField ID="hidid" runat="server" Value='<%# Eval("TypeCode") %>' />
                                    </td>
                                    <td class='STYLE10'>
                                        <%# Eval("Name")%>
                                        <%# Eval("Quantity")%> <%# Eval("Unit")%>
                                        <asp:HiddenField ID="hidPoint" runat="server" Value='<%# Eval("Point") %>' />
                                        <asp:HiddenField ID="hidName" runat="server" Value='<%# Eval("Name") %>' />
                                        
                                        <asp:HiddenField ID="hidRemark" runat="server" Value='<%# Eval("Remark") %>' />
                                         <asp:HiddenField ID="hidQuantity" runat="server" Value='<%# Eval("Quantity") %>' />
                                        <asp:HiddenField ID="TypeName" runat="server" Value='<%# Eval("TypeName") %>' />
                                      <asp:HiddenField ID="hidSingleNumber" runat="server" Value='<%# Eval("Quantity") %>' />
                                    </td>
                                    <td class='STYLE10'>
                                        <%# Eval("Point")%>
                                    </td>
                                    <td class='STYLE10' style="text-align: center">
                                        <%--      <asp:TextBox ID="txtScore"  onkeydown="myKeyDown()" Width="97%" ReadOnly="true" Text='<%# Eval("Highest") %>'
                                            runat="server"></asp:TextBox>--%>
                                        <asp:HiddenField ID="txtScore" runat="server" Value='<%# Eval("Highest") %>' />
                                        <%# Eval("Highest") %>
                                    </td>
                                    <td class='STYLE10'>
                                        <asp:TextBox ID="txtQuantity" Width="95%" onkeydown="myKeyDown()" onkeyup='Knum(this,"table1",1)'  MaxLength="3"   
                                            runat="server"></asp:TextBox>
                                    </td>
                                    <td class='STYLE10' style="text-align: center">
                                        <asp:TextBox ID="TextBox2" Width="95%" onkeydown="myKeyDown()" BorderStyle="None"  contenteditable="false"
                                            runat="server"></asp:TextBox>
                                    </td>
                                    
                                    <td  style="display: none">
                                        <%# Eval("Quantity")%>
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                        <tr>
                            <td>
                                总分:
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                                <input id="txtallnum1" value="0" style="width: 50px; color: Red; border-style: None"
                                    runat="server" name="txtallnum1" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                最低总分:
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                                <input id="txtTotal1" value="0" style="width: 50px; color: Red; border-style: None"
                                    runat="server" name="txtTotal1" readonly="readonly" type="text" />
                            </td>
                        </tr>
                    </tbody>
                </table>
            </asp:Panel>
            <div style="text-align: center">
                <asp:Button ID="btnAdd" runat="server" Text="部署完成" OnClientClick="return btnok()"
                    OnClick="btnAdd_Click" /><input id="Button1" type="button" value="关 闭" onclick="parent.ClosePop()" /></div>
        </div>

        <script type="text/javascript">
           
            function btnok() {
                //var dropPK = document.getElementById('dropPK').options[document.getElementById('dropPK').index]
                //var tbcell0 = document.getElementById(tablename).rows[rowIndex].cells[0].childNodes[0].checked; 
                var dropPK = document.getElementById('dropPK');

                var index = dropPK.selectedIndex; //序号，取当前选中选项的序号

                var val = dropPK.options[index].text;
                var ta = document.getElementById('table2');

                if (val != '请选择') {
                    var he1 = parseInt(document.getElementById('txtallnum2').value);
                    var he2 = parseInt(document.getElementById('txtTotal2').value);

                    if ((he1 - he2) < 0) {
                        alert('不能低于最低分数！');
                        return false;
                    }
                    var j = 0;
                    var k = 0;
                    for (var i = 1; i < ta.rows.length - 2; i++) {
                        var cell = ta.rows[i].cells[5].childNodes[0].value;

                        var chk = ta.rows[i].cells[1].childNodes[0].checked;
                        if (cell != "0" && chk == true) {
                            j++;
                        }
                        if (chk == true) {
                            k++;
                        }
                    }
                    if (k == 0 || j == 0) {
                        alert('请正确选择或填写数量！')
                        return false;
                    }
                    if (j == k) {
                        return true;
                    }
                    else {
                        alert('请正确选择或填写数量！')
                        return false;
                    }
                   
                }
                else {
                    var he1 = parseInt(document.getElementById('txtallnum1').value);
                    var he2 = parseInt(document.getElementById('txtTotal1').value);

                    if ((he1 - he2) <0) {
                        alert('不能低于最低分数！');
                        return false;
                    }
                   
                    ta = document.getElementById('table1');
                    var j = 0;
                    var k = 0;
                    for (var i = 1; i < ta.rows.length - 2; i++) {
                        var cell = ta.rows[i].cells[5].childNodes[0].value;

                        var chk = ta.rows[i].cells[1].childNodes[0].checked;
                        var cdk = ta.rows[i].cells[1].childNodes[0].disabled;
                        
                        if ((cell != "0" && chk == true)||cdk==true) {
                            j++;
                        }
                        if (chk == true || cdk == true) {
                            k++;
                        }
                       
                    }
                    if (k == 0 || j == 0) {
                        alert('请正确选择或填写数量！')
                        return false;
                    }
                    if (j == k) {
                        return true;
                    }
                    else {
                        alert('请正确选择或填写数量！')
                        return false;
                    }
                    
                    
                }
                return true;


            }
        </script>

    </div>
    </form>
</body>
</html>
